//
//  MyMessageViewController.m
//  Products_B
//
//  Created by lanou on 16/6/8.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "MyMessageViewController.h"
#import "MyMessageTableViewCell.h"
#define kLink(A,B) A##B
@interface MyMessageViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *privateTableView;
@property (nonatomic, strong) UITableView *personalTableView;
@property (nonatomic, strong) UITableView *systemTableView;
@property (nonatomic, strong) UIScrollView *scrollView;


@end

@implementation MyMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的消息";
    
    NSArray *items = @[@"私信",@"个人消息",@"系统消息"];
    for (int i = 0; i < 3; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(kWidth * i / 3, 64, kWidth / 3, 40);
        button.backgroundColor = [UIColor colorWithRed:239 / 255.0 green:239 / 255.0 blue:239 / 255.0 alpha:1];
        [button setTitle:items[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 100 + i;
        [self.view addSubview:button];
    }
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40 + 64, kWidth, kHeight - 40 - 64)];
    _scrollView.contentSize = CGSizeMake(kWidth * 3, kHeight - 40);
    _scrollView.contentOffset = CGPointMake(0, 0);
    _scrollView.delegate = self;
    _scrollView.bounces = NO;
    _scrollView.pagingEnabled = YES;
    [self.view addSubview:_scrollView];
    
    for (int i = 0; i < 3; i++) {
        UITableView *kLink(tableView,i) = [[UITableView alloc] initWithFrame:CGRectMake(kWidth * i, 0, kWidth, kHeight - 40 - 64) style:UITableViewStylePlain];
        kLink(tableView,i).dataSource = self;
        kLink(tableView, i).delegate = self;
        [_scrollView addSubview:kLink(tableView, i)];
        [tableViewi registerClass:[MyMessageTableViewCell class] forCellReuseIdentifier:@"myMessageTableViewCell"];
        
        if (i == 0) {
            _privateTableView = kLink(tableView, i);
        } else if (i == 1) {
            _personalTableView = kLink(tableView, i);
        } else {
            _systemTableView = kLink(tableView, i);
        }
    }
    
}

- (void)buttonAction:(UIButton *)button {
    if (button.tag == 100) {
        [_scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }
    if (button.tag == 101) {
        [_scrollView setContentOffset:CGPointMake(kWidth, 0) animated:YES];
    }
    if (button.tag == 102) {
        [_scrollView setContentOffset:CGPointMake(kWidth * 2, 0) animated:YES];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myMessageTableViewCell" forIndexPath:indexPath];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
